import java.io.File;
import java.io.IOException;

import org.codehaus.jackson.*;

public class Parse{
	public static void main(String[] args) throws JsonParseException, IOException{


		JsonFactory jfactory = new JsonFactory();

		/*** read from file ***/
		JsonParser jParser = jfactory.createJsonParser(new File("caro.json"));

		// loop until token equal to "}"
		while (jParser.nextToken() != JsonToken.END_OBJECT) {

			String fieldname = jParser.getCurrentName();
			if ("id".equals(fieldname)) {

				// current token is "name",
				// move to next, which is "name"'s value
				jParser.nextToken();
				System.out.println(jParser.getText()); // display mkyong

			}

			if ("age".equals(fieldname)) {

				// current token is "age", 
				// move to next, which is "name"'s value
				jParser.nextToken();
				System.out.println(jParser.getIntValue()); // display 29

			}

			if ("messages".equals(fieldname)) {

				jParser.nextToken(); // current token is "[", move next

				// messages is array, loop until token equal to "]"
				while (jParser.nextToken() != JsonToken.END_ARRAY) {

					// display msg1, msg2, msg3
					System.out.println(jParser.getText()); 

				}

			}

		}
		jParser.close();


	}
}